package com.jingbit.ai.sound;

import android.media.MediaPlayer;
import android.util.Log;

import java.io.IOException;

public class SoundPlayer {
    static MediaPlayer mPlayer;

    public static void startPlaying(MediaPlayer.OnCompletionListener listener,String fileName) {
        mPlayer = new MediaPlayer();
        try {
            mPlayer.setDataSource(fileName);
            mPlayer.prepare();
            mPlayer.start();
            mPlayer.setOnCompletionListener(listener);
        } catch (IOException e) {
            e.printStackTrace();
            Log.e("jingbit", "prepare failed");
        }
    }

    public static boolean isPlaying() {
        return mPlayer != null && mPlayer.isPlaying();
    }

    public static void stopPlaying() {
        mPlayer.release();
        mPlayer = null;
    }
}

